<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');

$sql_sel = "SELECT p.*"
		." FROM wfm_pagine p"
		." WHERE p.id_modulo = ".reqVarInt('idm')
		." ORDER BY p.cod_pagina ";
$objDB->query($sql_sel,'selRec');
$aRegPag = array();
while($acX = $objDB->fetch('selRec')) {
	if ($acX['id_regola_inp'])
		$aRegPag[$acX['id_regola_inp']][$acX['cod_pagina']] = $acX['descr'];
	if ($acX['id_regola_val'])
		$aRegPag[$acX['id_regola_val']][$acX['cod_pagina']] = $acX['descr'];
	if ($acX['id_regola_out'])
		$aRegPag[$acX['id_regola_out']][$acX['cod_pagina']] = $acX['descr'];
}
$sql_sel = "SELECT m.cod_modulo, m.descr as m_descr "
		.", r.* "
		." FROM wfm_moduli m " 
		." LEFT JOIN wfm_regole r ON r.id_modulo = m.id_modulo "
		." WHERE m.id_modulo = ".reqVarInt('idm')
		." ORDER BY r.tipo_regola, r.cod_regola ";
$objDB->query($sql_sel,'selRec');
$acX = $objDB->fetch('selRec');
if (!$acX) {
	backOnErr("id '".reqVarInt('idm')."' errato");
}
$cmdL = "";
$cmdR = "&nbsp;&nbsp;&nbsp;";
if (true) {
	$cmdR .= "<a class=\"cmd1\" href=\"regIns.php?idm=".reqVarInt('idm')."&$sXSNQS\">"._t("nuova regola")."</a>";
}
$cmdR .= cmdTorna(); 

$sHtmlMod = "<table class=\"tab1\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"100%\" align='center'>\n";
$sHtmlMod .= getHtmlRigaRif();
$sHtmlMod .= "<tr>\n";
$sHtmlMod .= "<td class='lab1' colspan='3'>Modulo</td>\n";
$sHtmlMod .= "<td class='txt1' colspan='3'>".$acX['cod_modulo']."</td>\n";
$sHtmlMod .= "<td class='txt1' colspan='14'>".$acX['m_descr']."</td>\n";
$sHtmlMod .= "</tr>\n";
$sHtmlMod .= "</table>";

$aOpz['sottotit'] = $sHtmlMod;

testaHtml('Gestione work-flow','Lista regole', $msgPag, 'wfma', $aOpz);
echo getHtmlForm();
echo getHtmlHidden('xsn',XSN);
echo getHtmlHidden('startoffset');
?>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
<? 
include "_inc/const.aTipiReg.php";
if (!empty($acX['id_regola'])) while($acX) { 
	$tipoReg = $acX['tipo_regola'];
?>
   <tr>
      <td class="tit1" colspan='4' align='left'>
      	<?="Regole ".$aTipiReg[$tipoReg]?>
      </td>
   </tr>
   <tr>
      <td class="lab1" width='1%' align='center'>ID</td>
      <td class="lab1" width='10%' align='center'>Codice</td>
      <td class="lab1" width='40%' align='center'>Descrizione</td>
      <td class="lab1" width='49%' align='center'>Pagine</td>
   </tr>
<?	
	$clRF = 'txt2';
	while($acX && $acX['tipo_regola'] == $tipoReg) {
		$clRF = ($clRF=='txt1')?'txt2':'txt1';	
?>
   <tr>
      <td class="<?=$clRF?>" align="right"><? echo $acX['id_regola'];?>&nbsp;</td>
      <td class="<?=$clRF?>" align="left">
      	<a href='regView.php?id=<?=$acX['id_regola']."&$sXSNQS"?>' class="<?=$clRF?>"
      	 	style='font-family:lucida console,courier;'><?echo $acX['cod_regola'];?></a>
      </td>
      <td class="<?=$clRF?>"><? echo $acX['descr'];?></td>
      <td class="<?=$clRF?>" align="left">
      	<? 
      	if (isset($aRegPag[$acX['id_regola']])) {
      		foreach($aRegPag[$acX['id_regola']] as $cX => $dX) {
      			echo $cX." - ".$dX."<br>";
      		}
      	} else {
      		echo "*** regola non utilizzata ***";
      	}
      	?>
      </td>
   </tr>
<?
		$acX = $objDB->fetch('selRec');
	}
}
?>
</table>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
</table>
<?
echo "</form>\n";
codaHtml();
exit();

